#pragma once

#ifdef __cplusplus
extern "C"
{
#endif
#include "li_list.h"

#define isUpper(c) ('A' <= (c) && (c) <= 'Z')
#define isLower(c) ('a' <= (c) && (c) <= 'z')
#define toUpper(c) ((c) & ~0x20)
#define toLower(c) ((c) | 0x20)
#define reLU(c) ((c) ^ 0x20)

#define isA(c) (isLower(c) || isUpper(c))
#define isD(c) ('0' <= (c) && (c) <= '9')

	char str_startwith(const char *s, const char *cmd);
	int32_t str_contains(const char *s, char c);
	int32_t str_contains_by_str(const char *s, char *c);
	char str_equal(const char *s, const char *cmd);
	int32_t str_index(const char *s, char c);
	int32_t str_index_right(char *s, char c);
	char str_lower(char *str);
	char str_replace(char *s, char from, char to);
	char str_replace_by_str(char *s, const char *from, char to);
	char *strReplace(const char *src, const char *from, const char *to);
	int32_t str_is_numeric(const char *name);
	int32_t str_is_name(const char *name);
	int32_t str_count_n(const char *str1, const char *str2);
	char int_to_string(int32_t n, char *s);

	float str_to_float(char *s);

	void str_insert_at(char *s, char c, int32_t at);

	float *get_nums_from_rx(char *rs, int32_t *length_back);
	char **get_paras_from_rx(char *rx, int32_t *len);

	void limit_to(float *x, float max);
	void limit_from_to(float *x, float lower, float upper);

	Li_List str_split(char *str, char split_char);

	Li_List str_split_by_str(char *str, const char *split_char);

	Li_List str_find(char *s, const char *find);

	Li_List str_find_sort(char *s, const char *find);

	// Li_String new_li_string_by(char *str);
	// use strdup() instead
	// char *new_string_by(char *str);

	// void delete_li_string(Li_String li);

	// int32_t assign_li_string(Li_String li, char *source);

	int32_t str_wrap(char *s, char c);
	int32_t str_wrap_by_str(char *s, const char *cs);

	int32_t str_left_wrap(char *s, char c);

	char *dynamic_str_cat(char *str, const char *sub);

	int str_translate(const char *_str, char *out);
	int str_translate2(const char *_str, char *out);
	int str_translate2_r(const char *_str, char *out);

	int str_translate_get_len(const char *_str, int*out);

	int str_translate_get_len_r(const char *_str, int *out);
	Li_List str_cmd_split(char *_str);

	Li_List str_count(char *str1, const char *str2);

#ifdef __cplusplus
}
#endif
